home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / nasm20 / nasm20s.zoo / lib / src / atou.s65 < prev    next >
Encoding:
Text File  |  1993-01-22  |  2.1 KB  |  101 lines

  1.    .include #macros
  2.    .include #16bit
  3.    
  4.    .zext _string1
  5.    .zext _value
  6.    .zext _tmp1
  7.  
  8. ;; -------------------------------------------------------------
  9. ;; Char in A
  10. ;; isdigit returns Carry set if true
  11. ;;                 Carry clr if false   
  12. ;; -------------------------------------------------------------
  13. isdigit:
  14.    cmp   #'9+1
  15.    bcs   :no
  16.    cmp   #'0
  17.    rts
  18. :no:
  19.    clc
  20.    rts   
  21.  
  22. ;; -------------------------------------------------------------
  23. ;; Convert a decimal number ASCII into an unsigned word
  24. ;; the input number must be decimal integer no sign
  25. ;; This function does not really check for overflow
  26. ;;                                  (maybe it should...)
  27. ;; string must end with $00 or $9B (ATASCII return)
  28. ;; Parameters via zeropage STRING1 and VALUE
  29. ;; returns: Carry set on success
  30. ;;          Carry clr on failure
  31. ;; -------------------------------------------------------------
  32. atou:
  33.    ldy   #0
  34.    tya
  35.    sta   _value
  36.    sta   _value+1
  37.    lda   (_string1),y
  38.    bne   :firsttime
  39.    clc
  40.    rts
  41.           
  42. :more
  43.    jsr   times10
  44.    lda   (_string1),y         ; _value += digit - '0'
  45. :firsttime   
  46.    jsr   isdigit
  47.    bcc   :failure
  48.    sbc   #'0                  ; no carry trix possible (sigh)
  49.    clc                
  50.    adc   _value
  51.    sta   _value
  52.    bcc   :convert
  53.    inc   _value+1
  54. :convert
  55.    iny
  56.    cpy   #5                   ; possibly superflous
  57.    bcs   :done
  58.    lda   (_string1),y
  59.    beq   :done
  60.    cmp   #$9B
  61.    bne   :more
  62.  
  63. :failure   
  64. :done
  65.    rts   
  66.       
  67.  
  68. ;; times10:
  69. ;; Multiplies a 16bit value with 10
  70. ;; the input number must be decimal integer no sign
  71. ;; This function does not really check for overflow
  72. ;;                                  (maybe it should...)
  73. ;; Parameters via zeropage _VALUE, tmp storage in _TMP1
  74. ;; returns: Carry contains oveflow (as expected) 
  75.  
  76. times10:
  77.    dmove _value,_tmp1
  78.    jsr   :val_lshift          ; _value *= 10
  79.    jsr   :val_lshift
  80.    jsr   :val_lshift
  81.    jsr   :val_a_tmp
  82.    
  83. :val_a_tmp:
  84.    adc.w _tmp1,_value,@special   ;; carry will be clear
  85.    bcs   :error
  86.    rts
  87.  
  88. :val_lshift:
  89.    asl.w _value
  90.    bcs   :error               ;; really success
  91. :success
  92.    rts  
  93.  
  94. :error
  95.    pla
  96.    pla
  97.    rts
  98.    
  99.  
  100.  
  101.